package com.mt.mtbletools;

import com.mt.mtbletools.R;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class AboutFragment extends Fragment {
	private Activity activity;

	public AboutFragment(Activity activity) {
		this.activity = activity;
	}

	private PackageManager manager;
	private PackageInfo info;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		manager = activity.getPackageManager();
		try {
			info = manager.getPackageInfo(activity.getPackageName(), 0);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
	}

	private TextView version_txt;
	private Button dirctbuy_btn;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_about, container, false);

		version_txt = (TextView) view.findViewById(R.id.version_txt);

		version_txt.setText("版本：MTBeacon(" + info.versionName + ")");

		dirctbuy_btn = (Button) view.findViewById(R.id.dirctbuy_btn);

		dirctbuy_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Uri uri = Uri.parse(
						"http://item.taobao.com/item.htm?spm=a1z10.1-c.w4004-9321083823.5.wmidBC&id=37352738955&qq-pf-to=pcqq.c2c");
				Intent it = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(it);
			}
		});

		return view;
	}
}
